C++ improvements in VCard. Add tests. (#750)
authorRobert Lipe <robertlipe@users.noreply.github.com>
Mon, 1 Nov 2021 05:49:57 +0000 (00:49 -0500)
committerGitHub <noreply@github.com>
Mon, 1 Nov 2021 05:49:57 +0000 (00:49 -0500)
* C++ improvements inside Vcard. Add test.
* Eternal impedance mismatch on C vs C++ pointer ownership.
* VCF: Incorporate review feedback: auote ','. Match HTML tage regardless of case.
* Quote commas in ASCII source, not just UTH8-encoded text.

reference/gc/GCGCA8~vcard.vcf [new file with mode: 0644]
testo.d/vcard.test [new file with mode: 0644]
vcf.cc

diff --git a/reference/gc/GCGCA8~vcard.vcf b/reference/gc/GCGCA8~vcard.vcf
new file mode 100644 (file)
index 0000000..cb0aaf5
--- /dev/null
@@ -0,0 +1,7 @@
+BEGIN:VCARD
+VERSION:3.0
+N:Oozy rat in a sanitary zoo;GCGCA8;;;
+ADR:N35 55.300 W86 51.700
+URL:http://www.geocaching.com/seek/cache_details.aspx?guid=cda94cd6-d657-49bd-8e7e-0031ef1b2613
+NOTE:The cache is not at the coordinates above.   These coords will get you to the correct park and within 1/2 mile of the cache.  The cache is within 35 feet of the trail.   It is not handicapped accessible.   It is a nice walk in the woods that is practical for all ages.  There is no space in the container for trading items.   You should bring a writing stick and bug spray is recommended.\nSo if the cache isn't at the above coordinates\, where is it?    Too bad I hid a boot Too hot to hoot Never odd or even Do geese see God? "Do nine men interpret?" "Nine men\," I nod Rats live on no evil star Go hang a salami\, I'm a lasagna hog  Now that it's intuitively obvious to even the most casual observer where the cache is\, turn on your geo-mojo and go find it. \n [IMG]\n\nHINT:\nThere Is No Hint
+END:VCARD
diff --git a/testo.d/vcard.test b/testo.d/vcard.test
new file mode 100644 (file)
index 0000000..188ce7b
--- /dev/null
@@ -0,0 +1,5 @@
+rm -f ${TMPDIR}/GCGCA8.vcf
+
+gpsbabel -i gpx -f ${REFERENCE}/gc/GCGCA8.gpx -o vcard -F ${TMPDIR}/GCGCA8.vcf
+compare ${TMPDIR}/GCGCA8.vcf ${REFERENCE}/gc/GCGCA8~vcard.vcf
+
diff --git a/vcf.cc b/vcf.cc
index da94b2c653e536ce449c995bc058d11ea16a4dc8..d5dc31d9682afb2080ccf75f3fc09a270c0a9644 100644 (file)
--- a/vcf.cc
+++ b/vcf.cc
@@ -64,15 +64,16 @@ vcf_print_utf(const utf_string* s)
     return;
   }
 
-  char* stripped_html = strip_html(s);
-  char* p = gstrsub(stripped_html, "\n", "\\n");
-  char* p2 = gstrsub(p, "<p>", "\\n");
-  char* p3 = gstrsub(p2, ";", "\\;");
-  gbfputs(p3, file_out);
-  xfree(p);
-  xfree(p2);
-  xfree(p3);
-  xfree(stripped_html);
+  char *string = strip_html(s);
+  QString stripped_html = string;
+  xfree(string);
+
+  stripped_html.replace("\n", "\\n", Qt::CaseInsensitive);
+  stripped_html.replace("<p>", "\\n", Qt::CaseInsensitive);
+  stripped_html.replace(";", "\\;");
+  stripped_html.replace(",", "\\,");
+
+  gbfputs(stripped_html, file_out);
 }
 
 static void
@@ -82,9 +83,10 @@ vcf_print(const char* s)
     return;
   }
 
-  char* p = gstrsub(s, "\n", "\\n");
-  gbfputs(p, file_out);
-  xfree(p);
+  QString cleaned = s;
+  cleaned.replace("\n", "\\n", Qt::CaseInsensitive);
+  cleaned.replace(",", "\\,");
+  gbfputs(cleaned, file_out);
 }
 
 static void
@@ -117,7 +119,7 @@ vcf_disp(const Waypoint* wpt)
     QString s = rot13(wpt->gc_data->hint);
     vcf_print(s);
   } else {
-    vcf_print(CSTR(wpt->gc_data->hint));
+    vcf_print(wpt->gc_data->hint);
   }
 
   gbfprintf(file_out, "\nEND:VCARD\n");